import 'package:flutter/material.dart';
import 'package:flutter_yfree/YFree.dart';
import 'package:flutter_yfree/main/YFree+Model.dart';

class ProductListModel {
  ProductListModel();

  late List<SearchMainModel> searchItems;
  late List<ProductListSubModel> productItems;

  ProductListModel.fromJson(Map<dynamic, dynamic> map) {
    searchItems = map.byList("searchItems", (rawValue) => SearchMainModel.fromJson(rawValue), defaultValue: [])!;
    productItems = map.byList("productItems", (rawValue) => ProductListSubModel.fromJson(rawValue), defaultValue: [])!;
  }
}

class ProductListSubModel {
  ProductListSubModel();

  late String id;
  late String img;
  late String title;
  late String money1;
  late String money2;
  late String count;
  late String des;
  late String likeContent;

  bool isSelect = false;

  ProductListSubModel.fromJson(Map<dynamic, dynamic> map) {
    id = map.byString("id", defaultValue: "")!;
    img = map.byString("img", defaultValue: "")!;
    title = map.byString("title", defaultValue: "")!;
    money1 = map.byString("money1", defaultValue: "")!;
    money2 = map.byString("money2", defaultValue: "")!;
    count = map.byString("count", defaultValue: "")!;
    des = map.byString("des", defaultValue: "")!;
    likeContent = map.byString("likeContent", defaultValue: "")!;
  }
}

class SearchMainModel {
  SearchMainModel();

  late String id;
  late String title;
  late List<SearchSubModel> items;
  late bool isSingle;
  late String value;

  BuildContext? dialogContext;
  ScrollController controller_searchBar_inner = ScrollController();

  SearchMainModel.fromJson(Map<dynamic, dynamic> map) {
    id = map.byString("id", defaultValue: "")!;
    title = map.byString("title", defaultValue: "")!;
    items = map.byList("items", (rawValue) => SearchSubModel.fromJson(rawValue), defaultValue: [])!;
    isSingle = map.byBool("isSingle", defaultValue: false)!;
    value = map.byString("value", defaultValue: "")!;
  }

  String toJson() => yToJson({
        "id": id,
        "items": items,
      });
}

class SearchSubModel {
  SearchSubModel();

  late String id;
  late String title;
  late bool isSelect;

  SearchSubModel.fromJson(Map<dynamic, dynamic> map) {
    id = map.byString("id", defaultValue: "")!;
    title = map.byString("title", defaultValue: "")!;
    isSelect = map.byBool("isSelect", defaultValue: false)!;
  }

  String toJson() => yToJson({
        "id": id,
        "isSelect": isSelect,
      });
}

class ProductDetailModel {
  ProductDetailModel();

  late String title;
  late String money;
  late bool isSave;
  late int count_carts;
  late int count_sales;
  late int count_replys;
  late List<ProductDetailModel_Asset> items_assets;
  late List<ProductDetailModel_Sku> items_sku;
  late List<ProductDetailModel_Param> items_param;
  late List<String> items_detail;
  late String serviceID;
  late String serviceName;
  late String serviceAvatar;

  ProductDetailModel.fromJson(Map<dynamic, dynamic> map) {
    title = map.byString("title", defaultValue: "")!;
    money = map.byString("money", defaultValue: "")!;
    isSave = map.byBool("isSave", defaultValue: false)!;
    count_carts = map.byInt("count_carts", defaultValue: 0)!;
    count_sales = map.byInt("count_sales", defaultValue: 0)!;
    count_replys = map.byInt("count_replys", defaultValue: 0)!;
    items_assets = map.byList("items_assets", (rawValue) => ProductDetailModel_Asset.fromJson(rawValue), defaultValue: [])!;
    items_sku = map.byList("items_sku", (rawValue) => ProductDetailModel_Sku.fromJson(rawValue), defaultValue: [])!;
    items_param = map.byList("items_param", (rawValue) => ProductDetailModel_Param.fromJson(rawValue), defaultValue: [])!;
    items_detail = map.byList("items_detail", (rawValue) => rawValue.toString(), defaultValue: [])!;
    serviceID = map.byString("serviceID", defaultValue: "")!;
    serviceName = map.byString("serviceName", defaultValue: "")!;
    serviceAvatar = map.byString("serviceAvatar", defaultValue: "")!;
  }
}

class ProductDetailModel_Asset {
  ProductDetailModel_Asset();

  late String img;
  late String video;

  ProductDetailModel_Asset.fromJson(Map<dynamic, dynamic> map) {
    img = map.byString("img", defaultValue: "")!;
    video = map.byString("video", defaultValue: "")!;
  }
}

class ProductDetailModel_Sku {
  ProductDetailModel_Sku();

  late String id;
  late String title;
  late String img;
  late String money;
  late int count_left;
  late int count_sales;
  late bool isSelect;

  ProductDetailModel_Sku.fromJson(Map<dynamic, dynamic> map) {
    id = map.byString("id", defaultValue: "")!;
    title = map.byString("title", defaultValue: "")!;
    img = map.byString("img", defaultValue: "")!;
    money = map.byString("money", defaultValue: "")!;
    count_left = map.byInt("count_left", defaultValue: 0)!;
    count_sales = map.byInt("count_sales", defaultValue: 0)!;
    isSelect = map.byBool("isSelect", defaultValue: false)!;
  }
}

class ProductDetailModel_Param {
  ProductDetailModel_Param();

  late String title;
  late String content;

  ProductDetailModel_Param.fromJson(Map<dynamic, dynamic> map) {
    title = map.byString("title", defaultValue: "")!;
    content = map.byString("content", defaultValue: "")!;
  }
}
